package com.Mobile.Action;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletResponseAware;
import com.Entity.GesWeeks;
import com.Service.GesWeeksService;

public class MobileWeekAction implements ServletResponseAware {

	private int flag=0;
	private HttpServletResponse response;//response对象

	private GesWeeksService gesweeksservice;
	private GesWeeks gesweeks;
	
	public GesWeeksService getGesweeksservice() {
		return gesweeksservice;
	}
	public void setGesweeksservice(GesWeeksService gesweeksservice) {
		this.gesweeksservice = gesweeksservice;
	}
	public GesWeeks getGesweeks() {
		return gesweeks;
	}
	public void setGesweeks(GesWeeks gesweeks) {
		this.gesweeks = gesweeks;
	}
	
	public void weekknowledge() throws ServletException, IOException {
		
		String weekid= ServletActionContext.getRequest().getParameter("weekid");
		response.setContentType("application/json;charset=utf-8");
		PrintWriter out = response.getWriter();
		
		JSONObject returnjson=new JSONObject();
		JSONArray jsonarray=new JSONArray();
		
		if(weekid!=null&&!weekid.equals("")){
			int intweekid=Integer.parseInt(weekid);
			gesweeks=this.gesweeksservice.getById(intweekid);
			if(gesweeks!=null){
				JSONObject jsonbean=JSONObject.fromObject(gesweeks);
				flag=1;
				returnjson.put("flag",flag);
				jsonarray.add(jsonbean);
				returnjson.put("info", jsonarray);				
			}
			else{
				returnjson.put("flag", flag);
			}
		}
		else{
			returnjson.put("flag", flag);
		}
		out.println(returnjson.toString());
		out.flush();
		out.close();
	}
	@Override
	public void setServletResponse(HttpServletResponse response) {
		// TODO Auto-generated method stub
		this.response=response;
	}
	
}
